package com.shop2cn.iapi.prodstock.testcase;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.prodstock.parameter.GetCatalogStockByProductInActivityIdListBean;
import com.shop2cn.iapi.prodstock.service.GetCatalogStockByProductInActivityIdListCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallServiceV2;
import com.ymttest.database.model.GodProductActivityStock;
import com.ymttest.database.sqlwapper.GodProductActivityStockWapper;
import com.ymttest.utils.AgentUsers;
/**
*获取商品活动库存数Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetCatalogStockByProductInActivityIdList{
	private static GetCatalogStockByProductInActivityIdListBean getcatalogstockbyproductinactivityidlistBean;
	private static GetCatalogStockByProductInActivityIdListCall getcatalogstockbyproductinactivityidlistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商品活动库存数Test");
	}

	@Before
	public void caseUp() {
		getcatalogstockbyproductinactivityidlistBean=new GetCatalogStockByProductInActivityIdListBean();
		getcatalogstockbyproductinactivityidlistCall=new GetCatalogStockByProductInActivityIdListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getcatalogstockbyproductinactivityidlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	// 渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	// 渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetCatalogStockByProductInActivityIdList_001() {
		Logger.start(true,"正确数据，成功");
		try {
			//活动20件，下单十件，之后订单取消，返还
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			AddactivityBean initProductaddactivity = AgentProductCallServiceV2.initProductaddactivity(rootUserId, productId,1,30, false);
			Integer activityId = AgentProductCallServiceV2.agentProductaddactivity(initProductaddactivity);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			GodProductActivityStock selectByProductId = new GodProductActivityStockWapper().selectByProductIdAndCatalogId(productId, productDetailsDto.getCatalogList().get(0).getCatalogId());
			getcatalogstockbyproductinactivityidlistBean.setProductInActivityIdList(Arrays.asList(selectByProductId.getiProductInActivityId()));
			getcatalogstockbyproductinactivityidlistCall.setData(getcatalogstockbyproductinactivityidlistBean);
			getcatalogstockbyproductinactivityidlistCall.callService();			
			Logger.verifyEquals("200", getcatalogstockbyproductinactivityidlistCall.getString("Code"), "验证code");
			Logger.verifyEquals(true, getcatalogstockbyproductinactivityidlistCall.getJsonObject().toString().indexOf("30")!=-1, "库存为30");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}